/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package geracaopdf;

import com.itextpdf.text.Anchor;
import com.itextpdf.text.BadElementException;
import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Chapter;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Element;
import com.itextpdf.text.Font;
import com.itextpdf.text.List;
import com.itextpdf.text.ListItem;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.Section;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import utils.Cliente;

/**
 *
 * @author Igor
 */
public class ClienteIndividualPDF {

    private static String file;
    private Cliente clienteEscolhido;
    private static Font catFont = new Font(Font.FontFamily.TIMES_ROMAN, 18,
            Font.BOLD);
    private static Font bigBold = new Font(Font.FontFamily.TIMES_ROMAN, 14,
            Font.BOLD);
    private static Font redFont = new Font(Font.FontFamily.TIMES_ROMAN, 12,
            Font.NORMAL, BaseColor.RED);
    private static Font subFont = new Font(Font.FontFamily.TIMES_ROMAN, 16,
            Font.BOLD);
    private static Font smallBold = new Font(Font.FontFamily.TIMES_ROMAN, 12,
            Font.BOLD);
    private static Font smallestBold = new Font(Font.FontFamily.TIMES_ROMAN, 6,
            Font.BOLD);
    private static Font capsNoBold = new Font(Font.FontFamily.TIMES_ROMAN, 12,
            Font.NORMAL);

    public ClienteIndividualPDF(Cliente clienteEscolhido) {
        this.clienteEscolhido = clienteEscolhido;
        Document document = new Document();
        file = "C:/Arquivos PDF/Clientes/" + clienteEscolhido.getCpf_cnpj() +clienteEscolhido.getNome() + ".pdf";
        try {
            try {
                PdfWriter.getInstance(document, new FileOutputStream(file));
                document.open();
                addMetaData(document);
                addTitlePage(document);
                document.close();
            } catch (FileNotFoundException ex) {
                Logger.getLogger(ClienteIndividualPDF.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (DocumentException ex) {
            Logger.getLogger(ClienteIndividualPDF.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void addMetaData(Document document) {
        document.addTitle("Dados referentes ao cliente " + clienteEscolhido.getNome());
        document.addSubject("Dados do cliente");
        document.addKeywords("Java, PDF," + clienteEscolhido.getNome());
        document.addAuthor("Frente de Caixa");
        document.addCreator("Frente de Caixa");
    }

    private void addTitlePage(Document document)
            throws DocumentException {
        Paragraph preface = new Paragraph();
        // We add one empty line
        addEmptyLine(preface, 2);
        // Lets write a big header
        preface.add(new Paragraph("Dados Referentes ao Cliente", catFont));

        addEmptyLine(preface, 2);
        // Will create: Report generated by: _name, _date
        preface.add(new Paragraph("Nome do Cliente:", bigBold));
        preface.add(new Paragraph(clienteEscolhido.getNome().toUpperCase(), capsNoBold));
        
        addEmptyLine(preface, 2);
        // Will create: Report generated by: _name, _date
        preface.add(new Paragraph("CPF/CNPJ do Cliente:", bigBold));
        preface.add(new Paragraph(clienteEscolhido.getCpf_cnpj().toUpperCase(), capsNoBold));
        
        addEmptyLine(preface, 2);
        // Will create: Report generated by: _name, _date
        preface.add(new Paragraph("Telefone do Cliente:", bigBold));
        preface.add(new Paragraph(clienteEscolhido.getTelefone().toUpperCase(), capsNoBold));
        
        addEmptyLine(preface, 2);
        // Will create: Report generated by: _name, _date
        preface.add(new Paragraph("Endereço do Cliente:", bigBold));
        preface.add(new Paragraph(clienteEscolhido.getEndereco().toUpperCase(), capsNoBold));
        
        addEmptyLine(preface, 2);
        // Will create: Report generated by: _name, _date
        preface.add(new Paragraph("Assinatura do Cliente:", bigBold));
        preface.add(new Paragraph("____________________________________________________________________________________", capsNoBold));
        
        
        addEmptyLine(preface, 16);
        // Will create: Report generated by: _name, _date
        Paragraph textoFinal = new Paragraph("Este relatório foi gerado pelo Frente de Caixa em:"+ new Date(), smallestBold);
        textoFinal.setAlignment(Element.ALIGN_CENTER);
        preface.add(textoFinal);
        
        document.add(preface);
        document.newPage();
        
    }


    private static void addEmptyLine(Paragraph paragraph, int number) {
        for (int i = 0; i < number; i++) {
            paragraph.add(new Paragraph(" "));
        }
    }

    public Cliente getClienteEscolhido() {
        return clienteEscolhido;
    }

    public void setClienteEscolhido(Cliente clienteEscolhido) {
        this.clienteEscolhido = clienteEscolhido;
    }
    
    
}
